﻿/******************************************************************
** 文 件 名: Bu_WeekReport_Other_DAL.cs
** Copyright (c) 2010-2012 Honestysoft (GuangZhou) Co.,LTD
** 创 建 人: 此代码由生成器自动生成
** 创建日期: 2012-6-9 17:21:19
** 描    述: 实现公共部分的数据访问封装，提供周报-其他事项的数据访问类
** 版    本: 2.0.0.0
** 修改描述:
** 修 改 人:
** 修改日期:
******************************************************************/
using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Text;
using Honestysoft.BaseObject;
using Honestysoft.Financing.Model;

namespace Honestysoft.Financing.DataAccess
{
	/// <summary>
    /// Bu_WeekReport_Other数据访问类
    /// </summary>
	public partial class Bu_WeekReport_Other_DAL : BaseDataAccess<Bu_WeekReport_Other>
    {		
		/// <summary>
        /// 构造函数，使用指定的连接字符串
        /// </summary>
        /// <param name="connectionStringName">连接字符串名称</param>
        public Bu_WeekReport_Other_DAL(string connectionStringName)
            : base(connectionStringName)
        {

        }

        public List<Bu_WeekReport_Other> GetWeekReportOther(int year, int week)
        {
            DbParameter pYear=CreateParameter("TheYear");
            pYear.DbType = DbType.Int32;
            pYear.Value = year;
            DbParameter pWeek = CreateParameter("Week");
            pWeek.DbType =  DbType.Int32;
            pWeek.Value = week;
            string sql = string.Format(@"Select * From Bu_WeekReport_Other
                    Where ID=(Select ID From Bu_WeekReport Where TheYear={0} And Week={1})", pYear.ParameterName, pWeek.ParameterName);
            DbCommand command = GetDbCommand(sql);
            command.Parameters.Add(pYear);
            command.Parameters.Add(pWeek);
            DataTable dt = ExecuteDataTable(command);
            return Honestysoft.BaseObject.DataMapping.TableToEntity<Bu_WeekReport_Other>(dt);
        }

        public int GetWeekReportOtherNextSortNo(string id)
        {
            DbParameter parameter = GetDbParameter("WeekReportID", id);
            string sql = string.Format(@"Select Max(SortNo) maxSortNo From Bu_WeekReport_Other Where WeekReportID={0}", parameter.ParameterName);
            DbCommand command = GetDbCommand(sql);
            command.Parameters.Add(parameter);
            object obj = ExecuteScalar(command);
            if (obj == null || obj == DBNull.Value) { return 1; }
            return Convert.ToInt32(obj) + 1;
        }
    }
}
